<template>
	<view>
		<view class="bslist-t">
			<view :class="tabIndex == 0 ? 'bslist-t-ac' : ''" @click="changeTab(0)">月度统计</view>
			<view :class="tabIndex == 1 ? 'bslist-t-ac' : ''" @click="changeTab(1)">年度统计</view>
		</view>
		<view class="money" v-if="toolPanel">
			<view class="">
				<text>本{{tabIndex==0?'月':'年'}}应收</text>
				<text>{{ toolPanel.receivableAccount }}</text>
			</view>
			<view class="">
				<text>本{{tabIndex==0?'月':'年'}}实收</text>
				<text style="color: #F16757;">{{ toolPanel.receivedAccount }}</text>
			</view>
			<view class="">
				<text>本{{tabIndex==0?'月':'年'}}代扣</text>
				<text>{{ toolPanel.receivableAccount - toolPanel.receivedAccount}}</text>
			</view>
		</view>
		<view class="lineEchart">
			<view class="years">
				<view @click="showDatePicker = true">{{ dateTxt }} <u-icon style="margin-left: 10rpx;" size="22" color="#333333" name="arrow-down"></u-icon>
				</view>
			</view>
			<view class="charts-box">
				<qiun-data-charts ref="ucharts"  type="line" :opts="opts" :chartData="chartData" :ontouch="true" :canvas2d="true" canvasId="xvdsfuha" background="none" />
			</view>
		</view>
		<view class="bslist-c-box" v-if="tcStatisticsList.length>0">
			<view class="bslist-c">
				<view class="bslist-col xb-card">
					<view class="bslist-col-t">
						<text>时间</text>
						<text>应收</text>
						<text>实收</text>
						<text>代扣</text>
					</view>
					<view class="bslist-col-s">
            <view class="bslist-col-c" v-for="(item, index) in tcStatisticsList" :key="index">
              <text>{{ item.staticDate }}</text>
              <text>{{ item.receivableAccount }}</text>
              <text>{{ item.receivedAccount }}</text>
              <text>{{ item.receivableAccount-item.receivedAccount }}</text>
            </view>
					</view>
				</view>
			</view>
		</view>
    <u-picker mode="time" v-model="showDatePicker" :params="datePickerParams" @confirm="datePickerConfirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
        toolPanel:null,
        showDatePicker:false,
        datePickerParams:{
          year: true,
          month: true,
          day: false,
          hour: false,
          minute: false,
          second: false
        },
        tcStatisticsList:[],
        calenderMode:'date',
				chartData: {
					"categories": [],
					"series": [{
							"name": "实收",
							"data": []
						},
						{
							"name": "应收",
							"data": []
						},
						{
							"name": "代扣",
							"data": []
						}
					]
				},
				opts: {
					"type": "line",
					"canvasId": "asdaf",
					"canvas2d": false,
					"background": "none",
					"animation": true,
					"timing": "easeOut",
					"duration": 1000,
					"rotate": false,
					"errorReload": true,
					"fontSize": 13,
					"fontColor": "#666666",
					"enableScroll": true,
					"touchMoveLimit": 60,
					"enableMarkLine": false,
					"dataLabel": false,
					"dataPointShape": true,
					"dataPointShapeType": "solid",
					"tapLegend": true,
					"padding": [
						-10,
						10,
						10,
						0
					],
					"xAxis": {
						"disabled": false,
						"axisLine": true,
						"axisLineColor": "#CCCCCC",
						"calibration": false,
						"fontColor": "#666666",
						"fontSize": 13,
						"rotateLabel": false,
						"itemCount": 5,
						"boundaryGap": "center",
						"disableGrid": true,
						"gridColor": "#CCCCCC",
						"gridType": "solid",
						"dashLength": 4,
						"gridEval": 1,
						"scrollShow": false,
						"scrollAlign": "left",
						"scrollColor": "#A6A6A6",
						"scrollBackgroundColor": "#EFEBEF",
						"format": ""
					},
					"yAxis": {
						"disabled": false,
						"disableGrid": false,
						"splitNumber": 5,
						"gridType": "dash",
						"dashLength": 2,
						"gridColor": "#CCCCCC",
						"showTitle": false,
						"data": []
					},
					"legend": {
						"show": true,
						"position": "top",
						"padding": 0,
						"margin": 20,
						"backgroundColor": "rgba(0,0,0,0)",
						"borderColor": "rgba(0,0,0,0)",
						"borderWidth": 0,
						"fontSize": 13,
						"fontColor": "#666666",
						"lineHeight": 11,
						"hiddenColor": "#CECECE",
						"itemGap": 10
					},
					"extra": {
						"line": {
							"type": "curve",
							"width": 2
						},
						"tooltip": {
							"showBox": true,
							"showArrow": false,
							"showCategory": false,
							"borderWidth": 0,
							"borderRadius": 0,
							"borderColor": "#000000",
							"borderOpacity": 0.7,
							"bgColor": "#000000",
							"bgOpacity": 0.7,
							"gridType": "dash",
							"dashLength": 4,
							"gridColor": "#CCCCCC",
							"fontColor": "#FFFFFF",
							"splitLine": true,
							"horizentalLine": false,
							"xAxisLabel": false,
							"yAxisLabel": false,
							"labelBgColor": "#FFFFFF",
							"labelBgOpacity": 0.5,
							"labelFontColor": "#666666"
						},
						"markLine": {
							"type": "solid",
							"dashLength": 4,
							"data": []
						}
					}
				},
        selectDate:'',
        dateTxt:'',//显示日期
				tabIndex: 0,
				dataList: [],
				pageInfor: {
					pageSize: 10,
					pageNum: 1,
					total: 0,
				},
				stateList: [0, 1],
				list: [{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
			};
		},
		onLoad(option) {

		},
		onReady() {
      let nowDate=new Date()
      this.dateTxt=`${nowDate.getFullYear()}年${nowDate.getMonth()+1}月`
      this.selectDate=`${nowDate.getFullYear()}-${nowDate.getMonth()+1}`
      this.getData()
		},
		methods: {
			changeTab(index) {
        let nowDate=new Date()
				this.tcStatisticsList = [];
        this.chartData={
          "categories": [],
              "series": [{
            "name": "实收",
            "data": []
          },
            {
              "name": "应收",
              "data": []
            },
            {
              "name": "代扣",
              "data": []
            }
          ]
        }
				this.tabIndex = index;
				if (index == 0) {
          this.dateTxt=`${nowDate.getFullYear()}年${nowDate.getMonth()+1}月`
          this.selectDate=`${nowDate.getFullYear()}-${nowDate.getMonth()+1}`
          this.datePickerParams.month=true
				} else if (index == 1) {
          this.dateTxt=`${nowDate.getFullYear()}年`
          this.selectDate=`${nowDate.getFullYear()}-1}`
          this.datePickerParams.month=false
				}
        this.getData()
			},
      datePickerConfirm(e){
        this.tcStatisticsList = [];
        this.chartData={
          "categories": [],
          "series": [{
            "name": "实收",
            "data": []
          },
            {
              "name": "应收",
              "data": []
            },
            {
              "name": "代扣",
              "data": []
            }
          ]
        }
        if (this.tabIndex===0){
          this.dateTxt=`${e.year}年${e.month}月`
          this.selectDate=`${e.year}-${e.month}`
        }else {
          this.dateTxt=`${e.year}年`
          this.selectDate=`${e.year}-1`
        }
        this.getData()
      },
      getData(){
        this.chartData.series=[]
        this.apis.parkingApi.tcStatistics({
          staticDate:this.selectDate,
          statisticType:this.tabIndex
        }).then(res=>{
          let tcStatisticsList=res.data.tcStatisticsList
          this.toolPanel=res.data.toolPanel
          let receivableAccountList=[]
          let receivedAccountList=[]
          let leList=[]
          let categories=[]
          tcStatisticsList.map(item=>{
            if (this.tabIndex==0){
              categories.push(item.staticDate.split('-')[2])
            }else {
              categories.push(item.staticDate.split('-')[1])
            }
            receivableAccountList.push(item.receivableAccount)
            receivedAccountList.push(item.receivedAccount)
            leList.push(item.receivableAccount-item.receivedAccount)
          })
          let series=[
            {
              "name": "实收",
              "data": receivableAccountList
            },
            {
              "name": "应收",
              "data": receivedAccountList
            },
            {
              "name": "代扣",
              "data": leList
            }
          ]
          this.chartData=JSON.parse(JSON.stringify({categories,series}))
          //this.$refs.ucharts.updateData({categories,series})
          this.tcStatisticsList=tcStatisticsList
        })
      }
		}
	};
</script>

<style lang="scss" scoped>
	$subheadColor:#111111;
	$titleColor:#333333;

	.bslist-t {
		width: 100vw;
		height: 90rpx;
		background: #ffffff;
		display: flex;
		justify-content: space-around;
		align-items: center;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		position: fixed;
		top: 0;
		/* #ifdef H5 */
		top: 88rpx;
		/* #endif */
		left: 0;
		z-index: 9;

		.bslist-t-ac {
			display: flex;
			align-items: center;
			position: relative;
			height: 100%;
			font-weight: 600;
			font-family: PingFangSC-Medium, PingFang SC;

			&::after {
				position: absolute;
				content: "";
				bottom: 0;
				left: 50%;
				width: 30rpx;
				height: 6rpx;
				background: #6cc04e;
				border-radius: 4rpx;
				transform: translateX(-50%);
			}
		}
	}

	.bslist-e {
		position: relative;
		background: rgba($color: #000000, $alpha: 0);
		padding: 0 200rpx;
		z-index: 1;
		top: 20rpx;
	}

	.money {
		display: flex;
		justify-content: space-between;
		margin-bottom: 20rpx;
		margin-top: 116rpx;
		border-radius: 12rpx;
		padding: 0 20rpx;

		view:nth-child(1) {
			margin-right: 20rpx;
		}

		view:nth-child(2) {
			margin-right: 20rpx;
		}

		view {
			display: flex;
			flex-direction: column;
			padding: 30rpx 0 30rpx 34rpx;
			width: 33%;
			background: #FFFFFF;
			border-radius: 12rpx;

			text:first-child {
				font-size: 26rpx;
				color: #666666;
				line-height: 36rpx;
				margin-bottom: 8rpx;
			}

			text:last-child {
				font-size: 44rpx;
				font-weight: 500;
				color: $titleColor;
			}
		}
	}

	.bslist-c-box {
		margin-top: 0rpx;
		padding: 20rpx;

		.bslist-c {
			.bslist-col {
				box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.06);
				margin-bottom: 20rpx;
				padding: 26rpx 32rpx;
				.bslist-col-t,
				.bslist-col-c {
					font-size: 28rpx;
					color: #666666;
					border-bottom: 2rpx solid #EEEEEE;
					display: flex;
					justify-content: space-between;

          &:last-child{
            border: none;
          }

					text {
						display: inline-block;
					}

					text:nth-child(1) {
						width: 164rpx;
						margin-right: 60rpx;
					}
				}

				.bslist-col-c {
					color: #333333;
					margin-top: 24rpx;
					padding-bottom: 24rpx;
				}

				.bslist-col-t {
					padding-bottom: 24rpx;
				}
			}
		}
	}

	.lineEchart {
		background: #FFFFFF;
		margin: 30rpx 20rpx 0 20rpx;
		padding: 30rpx 0 0 30rpx;

		.years {
			font-size: 28rpx;
			font-weight: 500;
			color: #333333;
			margin-bottom: 30rpx;
		}
	}

	/* 请根据需求修改图表容器尺寸，如果父容器没有高度图表则会显示异常 */
	.charts-box {
		width: 100%;
		height: 512rpx;
	}
</style>
